#!/bin/bash
#J.Zh.Wu Edit version 0.1
if [ $# -ne 1 ] ; then
echo "usage:---------------------------------"
echo "./relax.sh  id_name"
echo "for example: ./relax.sh  T0003 "
echo "---------------------------------------"
echo 
echo "exit!"
exit 1
fi

PATH_ALL="/public/home/users/qiang/rosetta3"
PATH_ALL_TEST="$PATH_ALL/human"
PATH_FASTA="$PATH_ALL/fasta"
cd $PATH_ALL_TEST

DIR_PATH="$PATH_ALL_TEST/$1"


cd $DIR_PATH/pdb





#prepare
ls S_*_*.pdb > cluster_list

#create cluster flags
echo "-database $PATH_ALL/rosetta3_database" > c_flags
echo "-in:file:l cluster_list" >> c_flags
echo "-radius 4">>c_flags
#end


$PATH_ALL/rosetta3_source/bin/cluster.linuxgccrelease @c_flags


#copy result
cd $DIR_PATH
mkdir result

cp $DIR_PATH/pdb/c.0.0.pdb $DIR_PATH/result/$1_1.pdb
cp $DIR_PATH/pdb/c.1.0.pdb $DIR_PATH/result/$1_2.pdb
cp $DIR_PATH/pdb/c.2.0.pdb $DIR_PATH/result/$1_3.pdb
cp $DIR_PATH/pdb/c.3.0.pdb $DIR_PATH/result/$1_4.pdb
cp $DIR_PATH/pdb/c.4.0.pdb $DIR_PATH/result/$1_5.pdb
#end all

echo "All Finished!"
echo "Please check $DIR_PATH/result dir!"


#========================================================
#assemble pdbs to ONE file
#=-=========================================================
cd $DIR_PATH/result
TargetName=$1
echo "PFRMAT   TS">${TargetName}.pdb
echo "TARGET "${TargetName}>>${TargetName}.pdb
echo "AUTHOR LenServer">>${TargetName}.pdb
echo "REMARK Predictor remarks">>${TargetName}.pdb
echo "METHOD Description of methods used">>${TargetName}.pdb
echo "METHOD Description of methods used">>${TargetName}.pdb
echo "METHOD Description of methods used">>${TargetName}.pdb

echo "MODEL  1">>${TargetName}.pdb
echo "PARENT  N/A ">>${TargetName}.pdb
cat  $DIR_PATH/result/${TargetName}_1.pdb>>${TargetName}.pdb
echo "END">>${TargetName}.pdb

echo "MODEL  2">>${TargetName}.pdb
echo "PARENT  N/A ">>${TargetName}.pdb
cat  $DIR_PATH/result/${TargetName}_2.pdb>>${TargetName}.pdb
echo "END">>${TargetName}.pdb

echo "MODEL  3">>${TargetName}.pdb
echo "PARENT  N/A ">>${TargetName}.pdb
cat  $DIR_PATH/result/${TargetName}_3.pdb>>${TargetName}.pdb
echo "END">>${TargetName}.pdb


echo "MODEL  4">>${TargetName}.pdb
echo "PARENT  N/A ">>${TargetName}.pdb
cat  $DIR_PATH/result/${TargetName}_4.pdb>>${TargetName}.pdb
echo "END">>${TargetName}.pdb

echo "MODEL  5">>${TargetName}.pdb
echo "PARENT  N/A ">>${TargetName}.pdb
cat  $DIR_PATH/result/${TargetName}_5.pdb>>${TargetName}.pdb
echo "END">>${TargetName}.pdb

cd $PATH_ALL

